home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / dbase / fiasco.lha / Fiasco_1.2 / Databases / FAQs / searchfaqs.rexx < prev    next >
OS/2 REXX Batch file  |  1996-04-09  |  7KB  |  301 lines

  1. /* SearchFaqs.rexx
  2.  * Copyright © 1995-1996 Nils Bandener
  3.  * Requires "Most" by Uwe Röhm
  4.  * Tested with Most v1.56
  5.  * $VER: searchfaqs.rexx 4.4 (9.4.96)
  6.  */
  7.  
  8. Options Results
  9. Address FIASCO
  10.  
  11. Signal on Syntax
  12. Signal on Halt
  13. Signal on Break_C
  14. Signal on Failure
  15.  
  16. F_LockGUI
  17.  
  18. /*
  19.  *  Get params
  20.  */
  21.  
  22. F_RequestString 'Text "Enter a string to search for:"'
  23. if rc ~= 0 then call Quit
  24. pat = Result
  25.  
  26. F_RequestNumber '1 Text "Start searching at record no.:"'
  27. if rc ~= 0 then call Quit
  28. start = result
  29.  
  30. F_RequestChoice '"Which records do you want to be searched?"' '"All|Marked only"'
  31.  
  32. if Result = 0 then
  33.     Monly = 1
  34. else
  35.     Monly = 0
  36.  
  37. F_RequestChoice '"Write Results to File?"' '"Yes|No"'
  38.  
  39. if Result = 1 then
  40.     WriteFile = 1
  41. else
  42.     WriteFile = 0
  43.  
  44. if WriteFile = 1 then do
  45.  
  46.     /*
  47.      * Get a file to write to
  48.      */
  49.  
  50.     F_RequestFile Savemode
  51.  
  52.     if rc ~= 0 then do
  53.  
  54.         F_UnlockGUI
  55.  
  56.         exit
  57.  
  58.     end
  59.  
  60.     FName = Result
  61.  
  62.     /*
  63.      *  Open the file
  64.      */
  65.  
  66.     if ~Open("o", FName, "write") then do
  67.  
  68.         F_RequestChoice '"Couldn`t open file"' '"Cancel"'
  69.  
  70.         F_UnlockGUI
  71.  
  72.         exit
  73.  
  74.     end
  75.  
  76. end
  77.  
  78. /*
  79.  *  Interactive searching puts up a requester on each occurence
  80.  */
  81.  
  82. F_RequestChoice '"Interactive Searching?"' '"Yes|No"'
  83.  
  84. if Result = 1 then
  85.     Interact = 1
  86. else
  87.     Interact = 0
  88.  
  89. F_CountRecs
  90. num = Result
  91.  
  92. say "Searching for" pat "... (Ctrl-C for break)"
  93.  
  94. F_SetStatus "Searching..."
  95.  
  96. /*
  97.  * If start is out of range, make it fit
  98.  */
  99.  
  100. if start > num then start = 1
  101. if start < 1 then start = 1
  102.  
  103. do i = start to num
  104.  
  105.    Address FIASCO
  106.  
  107.    F_Progress i num
  108.  
  109.    /*
  110.     *  Check for marking
  111.     */
  112.  
  113.    F_IsMarked i
  114.  
  115.    if (Monly = 1 & rc = 0) | (Monly = 0) then do
  116.  
  117.        F_GetFieldCont "File" Record i
  118.        file = Result
  119.  
  120.        /*
  121.         *  search for the pattern, write the results to t:found
  122.         */
  123.  
  124.        Address Command 'search >t:found' '"' || file || '"' '"' || pat || '"'
  125.  
  126.        if rc = 0 then do
  127.  
  128.             /*
  129.              *  something has been found, open the result file
  130.              */
  131.  
  132.            if open("f", "t:found", "read") then do
  133.  
  134.                 if ~eof("f") then do
  135.  
  136.                     say "*****" file ":"
  137.                     if Writefile = 1 then call writeln("o", "*****" file ":")
  138.  
  139.                     /* If SkipAd = 1, no Requester will be put up */
  140.  
  141.                     skipad = 0
  142.  
  143.                     do while ~eof("f")
  144.  
  145.                         ln = readln("f")
  146.  
  147.                         say ln
  148.  
  149.                         if Writefile = 1 then call writeln("o", ln)
  150.  
  151.                         if interact = 1 & skipad = 0 then do
  152.  
  153.                             Parse var ln Line Rest
  154.  
  155.                             if length(line) > 0 then do
  156.  
  157.                                 Address FIASCO
  158.  
  159.                                 rest = compress(rest, '"*')
  160.                                 if length(rest) > 75 then rest = left(rest, 75)
  161.  
  162.                                 F_RequestChoice '"Found Pattern in File*n' || file || '*nLine ' || Line || '*n' || Rest || '"' '"Display|Next occurence|Next file|Break"'
  163.  
  164.                                 if Result = 1 then do
  165.  
  166.                                     found = 0
  167.                                     retry = 0
  168.  
  169.                                     do while found = 0
  170.  
  171.                                         retry = retry + 1
  172.  
  173.                                         if ~show(ports, "MOST.0") then do
  174.  
  175.                                             address command
  176.                                             "run most" file
  177.                                             "sys:rexxc/waitforport MOST.0"
  178.                                         end
  179.  
  180.                                         if show(ports, "MOST.0") then do
  181.  
  182.                                             Address MOST.0
  183.  
  184.                                             GetFileList
  185.                                             FileList = Result
  186.  
  187.                                             k = 1
  188.  
  189.                                             do while k <= words(FileList) & found = 0
  190.  
  191.                                                 filepos = lastpos("/", file)
  192.                                                 if filepos = 0 then filepos = lastpos(":", file)
  193.                                                 if filepos ~= 0 then filepos = filepos + 1
  194.  
  195.                                                 if upper(word(FileList, k)) = upper(substr(file,filepos)) then do
  196.  
  197.                                                     found = 1
  198.  
  199.                                                     /* Skip Strings like 1/1 */
  200.                                                     if pos("/", word(FileList, k + 1)) ~= 0 then k = k + 1
  201.  
  202.                                                     host = word(FileList, k + 1)
  203.  
  204.                                                     Interpret "Address" host
  205.                                                     tofront
  206.  
  207.                                                 end
  208.  
  209.                                                 k = k + 2
  210.                                             end
  211.  
  212.                                             if found = 0 then do
  213.  
  214.                                                 if retry = 1 then do
  215.                                                     address command
  216.  
  217.                                                     "run sys:rexxc/rx runmost" file
  218.                                                 end
  219.                                                 else if retry = 2 | retry = 3 then do
  220.                                                     address command
  221.  
  222.                                                     wait 1 sec
  223.                                                 end
  224.                                                 else break
  225.  
  226.                                             end
  227.                                         end
  228.                                     end
  229.  
  230.                                     if found = 1 then do
  231.  
  232.                                         Interpret "Address" host
  233.  
  234.                                         goto 'line' line
  235.                                     end
  236.                                 end
  237.                                 else if Result = 3 then do
  238.  
  239.                                     skipad = 1
  240.  
  241.                                 end
  242.                                 else if Result = 0 then do
  243.  
  244.                                     call close("f")
  245.  
  246.                                     if Writefile = 1 then call close("o")
  247.  
  248.                                     Address FIASCO
  249.  
  250.                                     F_UnlockGUI
  251.  
  252.                                     F_ResetStatus
  253.  
  254.                                     exit
  255.  
  256.                                 end
  257.                             end
  258.                         end
  259.  
  260.                     end
  261.                 end
  262.  
  263.                 call close("f")
  264.  
  265.            end
  266.         end
  267.    end
  268. end
  269.  
  270. if Writefile = 1 then do
  271.  
  272.     call close("o")
  273.  
  274. end
  275.  
  276. say "Done"
  277.  
  278. F_UnlockGUI
  279. F_ResetStatus
  280.  
  281. exit
  282.  
  283. Syntax:
  284. Failure:
  285. say "Error" rc "in line" sigl ":" errortext(rc)
  286. say file pat
  287.  
  288. Halt:
  289. Break_C:
  290. Quit:
  291.  
  292. Address FIASCO
  293.  
  294. F_UnlockGUI
  295. F_ResetStatus
  296.  
  297. say "Break"
  298.  
  299. exit
  300.  
  301.